package cn.NewsServlet;

import cn.NewsDao.NewsDao1;
import cn.NewsDaoImpl.NewsDaoImpl1;
import cn.entity.News1;
import cn.entity.Text1;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/add")
public class AddServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        System.out.println("这是get请求");

    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String userName=req.getParameter("userName");
        String password=req.getParameter("password");


        News1 news = new News1();
        news.setCategoryId(Integer.parseInt(userName) );
        news.setTitle(password);
        NewsDao1 newsDao1 = new NewsDaoImpl1();
        if (newsDao1.add(news)){
//            resp.sendRedirect("");
            req.getRequestDispatcher("index2.jsp").forward(req,resp);
            //resp.sendRedirect(req.getContextPath()+"/index2.jsp");
        }else {
            System.out.println("sddsdfs");
        }
    }
}
